import type { Plugin } from 'vite'
import { resolve } from 'node:path'
import process from 'node:process'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import UnoCSS from 'unocss/vite'
import { defineConfig, loadEnv } from 'vite'
import { wxcn } from './packages/vite-plugins'
import wxcnCfg from './wxcn.config.json'
// https://vite.dev/config/
export default defineConfig(async ({ mode }) => {
  const { VITE_PORT } = loadEnv(mode, process.cwd())
  return {
    plugins: [
      vue(),
      vueJsx(),
      wxcn(wxcnCfg) as Plugin[],
      UnoCSS(),
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
      },
    },
    server: {
      port: +VITE_PORT,
    },
  }
})
